package com.cf.system.controller;

import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.cf.common.result.Result;
import com.cf.system.entity.Tenant;
import com.cf.system.service.TenantService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ChenFeng
 * @date 2021/11/4 6:45 下午
 * @description
 */
@RestController
@RequestMapping("/tenant")
@AllArgsConstructor
public class TenantController {

    private final TenantService tenantService;

    @GetMapping("/info")
    public Result info(String domain) throws Exception {
        Tenant tenant = tenantService.getOne(Wrappers.<Tenant>query().lambda().eq(Tenant::getDomain, domain));
        if (tenant == null) {
            throw new Exception("租户异常");
        }
        return Result.success(MapUtil.builder().put("tenantId", tenant.getTenantId())
                .put("domain", tenant.getDomain())
                .put("backgroundUrl", tenant.getBackgroundUrl())
                .build());
    }

}
